package com.yuxue.petlog.logger;

import com.yuxue.petlog.payment.Payment;
import com.yuxue.petlog.product.Product;
import com.yuxue.petlog.user.User;
import com.yuxue.petlog.webpage.Page;
// 打印日志格式
public class Logger {
    private User user;
    private Page page;
    private Product product;
    private Payment payment;
    private int amount;

    public Logger(User user, Page page, Product product, Payment payment, int amount) {
        this.user = user;
        this.page = page;
        this.product = product;
        this.payment = payment;
        this.amount = amount;
    }

    public String getLogMessage() {
        StringBuilder logMessage = new StringBuilder();
        logMessage.append(user.getName()).append("在 ").append(page.getPageName()).append(" 使用 ")
                .append(payment.getMethodName()).append(" ")
                .append(payment.getActionVerb()).append(" ")
                .append(product.getDescription()).append("，")
                .append(payment.getCostDescription(amount));

        // 只有当 isWarning() 返回 true 时，才追加警告信息
        if (payment.isWarning(amount)) {
            logMessage.append(payment.getWarningMessage());
        }

        return logMessage.toString();
    }
}

